/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var fetchProperties = require("../constant/fetchProperties");
	var gridEvents = require("../handler/gridEvents");
	
    var instance = {
        initComponent: function (params, widget) {
        	var grid = new Grid({
        	    parentNode: ".J-grid",
        	    autoRender: false,
        	    model: {
        	        url: "api/checkin/query",
        	        params: function() {
        	        	var subnav = widget.get("subnav");
        	        	var pkServicePoint = subnav.getValue("servicePoint");
        	        	var pkBuilding = subnav.getValue("buildings");
        	        	var checkOutStatus = subnav.getValue("checkOutStatus");
        	        	var checkInDate = subnav.getValue("travelDate");
        	        	
        	            return {
        	            	"servicePoint.pkServicePoint":pkServicePoint,
        	            	"roomRegister.room.orgBuilding":pkBuilding,
        	            	"checkOutStatus":checkOutStatus,
        	            	"checkOutDate":checkInDate.start,
        	            	"checkOutDateEnd":checkInDate.end,
        	            	"fetchProperties":fetchProperties.grid
        	            };
        	        },
        	        columns: [{
        	            name: "roomRegister.room.orgBuilding.name",
        	            label: "楼宇"
        	        }, {
        	            name: "roomRegister.room.code",
        	            label: "房号"
        	        }, {
        	            name: "roomRegister.room.roomType.name",
        	            label: "房型"
        	        }, {
        	            name: "checkInDate",
        	            label: "入住日期",
        	            format: "date",
        	            formatparams: {
        	                mode: "YYYY-MM-DD"
        	            }
        	        }, {
        	            name: "checkInImplement.groupReserve.checkInType.value",
        	            label: "入住类型",
        	            format: function(value, row){
        	            	if(value){
        	            		return value;
        	            	}else{
        	            		return "散客";
        	            	}
        	            }
        	        }, {
        	            name: "checkOutStatus.value",
        	            label: "状态"
        	        }, {
        	            name: "checkOutDate",
        	            label: "退房日期",
        	            format: "date",
        	            formatparams: {
        	                mode: "YYYY-MM-DD"
        	            }
        	        }, {
        	            name: "",
        	            label: "操作",
        	            format: "button",
        	            formatparams: [{
        	                id: "checkout",
        	                text: "查房",
        	                show:function(index, data, rowEL){
        	                	if(data.checkOutStatus && data.checkOutStatus.key == "NoCheckOut"){
        	                		return true
        	                	}else{
        	                		return false;
        	                	}
        	                	 
        	                },
        	                handler: function(index, data, rowEL) {
        	                	widget.detail = false;
        	                	widget.handler.gridHandler.checkout(data,widget);
        	                }
        	            }, {
        	                id: "show",
        	                text: "查看",
        	                handler: function(index, data, rowEL) {
        	                	widget.detail = true;
        	                	widget.handler.gridHandler.checkout(data,widget);
        	                }
        	            }]
        	        }]
        	    }
        	});
        	widget.set("grid",grid);
        }
    };
    module.exports = instance;
});
